<?php
/**
 * @Author: Marte
 * @Date:   2017-08-09 14:59:29
 * @Last Modified by:   Marte
 * @Last Modified time: 2017-08-21 22:27:04
 */
header("Content-Type: text/html; charset=utf-8");
include "data/config_connect.php";
// //获取要显示的页数
if(isset($_GET['page']))
{
  $_page=$_GET['page'];
  if(empty($_page)||$_page<=0||!is_numeric($_page))
  {
     $_page=1;
  }
  else
  {
    $_page=intval($_page);//取整
  }
}
else
{
  $_page=1;
}
// 分页效果
$_pagesize=20;//每页有几条
$_pagenum=($_page-1)*$_pagesize;//每页第一个
mysqli_query($_mysql,"SELECT bookid FROM books");
// echo;
$_pagesnum=ceil(mysqli_affected_rows($_mysql)/$_pagesize);//共有几页
//如果$_page>总页数
if($_page>$_pagesnum)
{
  $_page=$_pagesnum;
}


// // 分类效果
// if(isset($_GET['all']))
// {
//   // 显示部分
//   $sort=$_GET['all'];

// }else
// {
//   $sort=0;

//   //默认是显示全部
// }

// // 按照是否完结来分类
// if(isset($_GET['end']))
// {
//   // 显示部分
//   $end=$_GET['end'];

// }else
// {
//   $end=0;
//   //默认是显示全部
// }

if(isset($_GET['all'])&&!isset($_GET['end']))
{
  if(!isset($_GET['word']))
  {
    $sort=$_GET['all'];
    $end=0;
    $word=0;
  }else{
    $sort=$_GET['all'];
    $end=0;
    $word=$_GET['word'];
  }

}else if(isset($_GET['all'])&&isset($_GET['end']))
{
   if(!isset($_GET['word']))
  {
    $sort=$_GET['all'];
    $end=$_GET['end'];
    $word=0;
  }else{
    $sort=$_GET['all'];
    $end=$_GET['end'];
    $word=$_GET['word'];
  }

}else if(!isset($_GET['all'])&&!isset($_GET['end']))
{
   if(!isset($_GET['word']))
  {
    $sort=0;
    $end=0;
    $word=0;
  }else{
    $sort=0;
    $end=0;
    $word=$_GET['word'];
  }
}else if(!isset($_GET['all'])&&isset($_GET['end']))
{
  if(!isset($_GET['word']))
  {
    $sort=0;
    $end=$_GET['end'];
    $word=0;
  }else{
    $sort=0;
    $end=$_GET['end'];
    $word=$_GET['word'];
  }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>墨悦轩书城</title>
    <link rel="stylesheet" type="text/css" href="css/allbooks.css">
    <script src="js/allbooks1.js" type="text/javascript" charset="utf-8"></script>
    <!-- jq框架 -->
    <script src="js/allbooks.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div class="top">
    <div class="w t_cen">
        <div class="t_c_logo"><a href="index.html"><img src="images/alllogo1.png" /></a></div>
        <div class="t_c_lr t_c_left"></div>
        <div class="t_c_cen">
            <div class="t_c_top">
             <?php

            session_start();

            if(!isset($_SESSION['username']))
            {
                echo '<span>欢迎您来到墨悦轩！请<a href="dl.php" title="">登录</a>或<a href="zc.php" title="">免费注册</a></span>';
                  // unset($_SESSION['username']);
            }else
            {
                echo '<span>欢迎<a href="person.php">'.$_SESSION['username'].'</a>来到墨悦轩！<a href="data/user/logout.php?exit=1" >退出</a></span>';

            }

            ?>
           <!--  <span>欢迎您来到墨悦轩！请<a href="dl.php" title="">登录</a>或<a href="zc.php" title="">免费注册</a></span> -->
                    <ul>
                        <li class="active"><a href="allbooks.php" title="">墨轩书城</a></li>
                        <li><a href="author_dl.php" title="">作者专区</a></li>
                        <li><a href="person.php" title="">个人中心</a></li>
                        <li><a href="index.php" title="">墨轩首页</a></li>
                        <li><a href="mybookrack.php" title="">朕的书架</a></li>
                    </ul>
            </div>
            <div class="t_c_bottom">
                <ul>
                    <li class="thisli">
                        <a href="allbooks.php"><em>墨悦书城</em><i>Home</i></a>
                    </li>
                    <li>
                        <a href="#"><em>作品分类</em><i>Categories</i></a>
                        <div class="Nodes">
                            <img src="images/menu_top.png" />
                            <ul>
                                <li><a href="#">玄幻奇幻</a></li>
                                <li><a href="#">古代言情</a></li>
                                <li><a href="#">仙侠奇缘</a></li>
                                <li><a href="#">现代都市</a></li>
                                <li><a href="#">网游竞技</a></li>
                                <li><a href="#">悬疑灵异</a></li>
                                <li><a href="#">科幻空间</a></li>
                                <li><a href="#">N次元</a></li>
                                <li><a href="#">浪漫校园</a></li>
                                <li><a href="#">军事历史</a></li>

                            </ul>
                            <img src="images/menu_bottom.png" />
                        </div>
                    </li>
                    <li>
                        <a href="#"><em>排行</em><i>Ranking</i></a>
                        <div class="Nodes">
                            <img src="images/menu_top.png" />

                            <img src="images/menu_bottom.png" />
                        </div>
                    </li>
                    <li>
                        <a href="#"><em>完本</em><i>End </i></a>
                        <div class="Nodes">
                            <img src="images/menu_top.png" />

                            <img src="images/menu_bottom.png" />
                        </div>
                    </li>
                    <li>
                        <a href="#"><em>免费</em><i>FREE</i></a>
                        <div class="Nodes">
                            <img src="images/menu_top.png" />

                            <img src="images/menu_bottom.png" />
                        </div>
                    </li>
                    <li>
                        <a href="author_dl.php"><em>作家专区</em><i>Writers</i></a>
                        <div class="Nodes">
                            <img src="images/menu_top.png" />

                            <img src="images/menu_bottom.png" />
                        </div>
                    </li>
                    <li>
                        <a href="#"><em>微信端</em><i>WeChat</i></a>
                        <div class="Nodes">
                            <img src="images/menu_top.png">

                            <img src="images/menu_bottom.png" />
                        </div>
                    </li>
                    <li>
                        <a href="#"><em>联系我们</em><i>Contact</i></a>
                    </li>
                </ul>
                <div class="thisMenu" id="thisMenu"></div>
            </div>
        </div>
        <div class="t_c_lr t_c_right"></div>
    </div>
</div>
<div class="main">
    <div class="main-left">
       <ul class="top1">
           <li class="boy">男生</li>
           <li class="girl">女生</li>
       </ul>
       <div class="yixuan">
           <span class="yixuan_title">已选</span>
           <ul>
               <li>全部</li>
           </ul>
       </div>
       <div class="sort">
           <span class="sort_title">分类</span>
           <ul>
               <li class="active1"><a href="allbooks.php?all=0" title="">全部</a></li>
               <li><a href="allbooks.php?all=1&end=<?php echo $end;?>&word=<?php echo $word;?>" title="">玄幻</a></li>
               <li><a href="allbooks.php?all=2&end=<?php echo $end;?>&word=<?php echo $word;?>" title="">奇幻</a></li>
               <li><a href="allbooks.php?all=3&end=<?php echo $end;?>&word=<?php echo $word;?>" title="">武侠</a></li>
              <li><a href="allbooks.php?all=4&end=<?php echo $end;?>&word=<?php echo $word;?>" title="">仙侠</a></li>
               <li><a href="allbooks.php?all=5&end=<?php echo $end;?>&word=<?php echo $word;?>" title="">都市</a></li>
               <li><a href="allbooks.php?all=6&end=<?php echo $end;?>&word=<?php echo $word;?>" title="">现实</a></li>
                <li><a href="allbooks.php?all=7&end=<?php echo $end;?>&word=<?php echo $word;?>" title="">历史</a></li>
               <li><a href="allbooks.php?all=8&end=<?php echo $end;?>&word=<?php echo $word;?>" title="">军事</a></li>
               <li><a href="allbooks.php?all=9&end=<?php echo $end;?>&word=<?php echo $word;?>" title="">校园</a></li>
                <li><a href="allbooks.php?all=10&end=<?php echo $end;?>&word=<?php echo $word;?>" title="">游戏</a></li>
               <li><a href="allbooks.php?all=11&end=<?php echo $end;?>&word=<?php echo $word;?>" title="">言情</a></li>
               <li><a href="allbooks.php?all=12&end=<?php echo $end;?>&word=<?php echo $word;?>" title="">灵异</a></li>
                <li><a href="allbooks.php?all=13&end=<?php echo $end;?>&word=<?php echo $word;?>" title="">N次元</a></li>

           </ul>
       </div>

       <div class="tai">
           <span class="tai_title">状态</span>
           <ul>
               <li class="active1"><a href="allbooks.php?end=0" title="">全部</a></li>
                <li><a href="allbooks.php?end=1&all=<?php echo $sort;?>&word=<?php echo $word;?>" title="">连载</a></li>
                <li><a href="allbooks.php?end=2&all=<?php echo $sort;?>&word=<?php echo $word;?>" title="">完本</a></li>
           </ul>
       </div>

       <div class="tai shu">
           <span class="tai_title">属性</span>
           <ul>
               <li><a href="" title="">全部</a></li>
                <li class="active1"><a href="" title="">免费</a></li>
                <li><a href="" title="">VIP</a></li>
           </ul>
       </div>


       <div class="zishu">
           <span class="zishu_title">字数</span>
           <ul>
               <li class="active1"><a href="allbooks.php?end=<?php echo $sort;?>&all=<?php echo $sort;?>&&word=0" title="">全部</a></li>
               <li><a href="allbooks.php?end=<?php echo $end;?>&all=<?php echo $sort;?>&&word=1" title="">30万字以下</a></li>
               <li><a href="allbooks.php?end=<?php echo $end;?>&all=<?php echo $sort;?>&&word=2" title="">30-50</a></li>
               <li><a href="allbooks.php?end=<?php echo $end;?>&all=<?php echo $sort;?>&&word=3" title="">50-80</a></li>
               <li><a href="allbooks.php?end=<?php echo $end;?>&all=<?php echo $sort;?>&&word=4" title="">80-120</a></li>
               <li><a href="allbooks.php?end=<?php echo $end;?>&all=<?php echo $sort;?>&&word=5" title="">120-200</a></li>
               <li><a href="allbooks.php?end=<?php echo $end;?>&all=<?php echo $sort;?>&&word=6" title="">200万字以上</a></li>

           </ul>
       </div>
        <div class="sort1">
           <span class="sort1_title">分类</span>
           <ul>
               <li class="active1"><a href="" title="">全部</a></li>
               <li><a href="" title="">豪门</a></li>
               <li><a href="" title="">孤儿</a></li>
               <li><a href="" title="">盗贼</a></li>
              <li><a href="" title="">黑客</a></li>
               <li><a href="" title="">特工</a></li>
               <li><a href="" title="">老师</a></li>
                <li><a href="" title="">明星</a></li>
               <li><a href="" title="">魔王附体</a></li>
               <li><a href="" title="">LOL</a></li>
                <li><a href="" title="">游戏</a></li>
               <li><a href="" title="">无敌文</a></li>
               <li><a href="" title="">争霸流</a></li>


           </ul>
       </div>
    </div>
    <div class="main_right">
        <ul class="list">
            <li class="active2"><a href="" title="">人气排序</a></li>
            <li><a href="" title="">按收藏</a></li>
            <li><a href="" title="">按最新</a></li>
            <li><a href="" title="">按推荐度</a></li>
        </ul>
        <span class="total">共有<?php
            mysqli_query($_mysql,"SELECT bookid FROM books");
            $_num=mysqli_affected_rows($_mysql);
            echo $_num;
        ?>本</span>

        <div class="total_book">


            <ul>
             <?php

        switch($end)
        {
            case 1:$isend=0;break;
            case 2:$isend=1;break;

        }
        switch($sort)
                {
                  case 1:$typeid=1;break;
                  case 2:$typeid=2;break;
                  case 3:$typeid=3;break;
                  case 4:$typeid=4;break;
                  case 5:$typeid=5;break;
                  case 6:$typeid=6;break;
                  case 7:$typeid=7;break;
                  case 8:$typeid=8;break;
                  case 9:$typeid=9;break;
                  case 10:$typeid=10;break;
                  case 11:$typeid=11;break;
                  case 12:$typeid=12;break;
                  case 13:$typeid=13;break;
                }
          switch($word)
          {
            case 1:$start=0;$stop=30;break;
            case 2:$start=30;$stop=50;break;
            case 3:$start=50;$stop=80;break;
            case 4:$start=80;$stop=120;break;
            case 5:$start=120;$stop=200;break;
            case 6:$start=200;$stop=1000;break;

          }

      if($end==0&&$sort!=0)
    {
      if($word==0)
      {
       $_result=$_mysql->query("select * from books where  typeid='$typeid' limit $_pagenum,$_pagesize;");
      }else{
        $_result=$_mysql->query("select * from books where  typeid='$typeid' and words between $start and $stop limit $_pagenum,$_pagesize;");
      }
    }else if($end==0&&$sort==0)
    {
      if($word==0)
      {
       $_result=$_mysql->query("select * from books  limit $_pagenum,$_pagesize;");
      }
      else{
      $_result=$_mysql->query("select * from books where words between $start and $stop   limit $_pagenum,$_pagesize;");
      }

    }else if($end!=0&&$sort==0)
    {
      if($word==0)
      {
        $_result=$_mysql->query("select * from books where isend='$isend'  limit $_pagenum,$_pagesize;");
      }
      else{
        $_result=$_mysql->query("select * from books where isend='$isend' and words between $start and $stop  limit $_pagenum,$_pagesize;");
      }

    }
    else if($end!=0&&$sort!=0)
    {
      if($word==0)
      {
       $_result=$_mysql->query("select * from books where isend='$isend' and typeid='$typeid' limit $_pagenum,$_pagesize;");
      }else{
        $_result=$_mysql->query("select * from books where isend='$isend' and typeid='$typeid' and words between $start and $stop  limit $_pagenum,$_pagesize;");
      }
    }

                while($_assoc=$_result->fetch_assoc())
                {
            ?>
                <li>
                    <div class="i_left">
                        <i><a href="bookinfo.php?id=<?php echo $_assoc['bookid']?>" title=""><img src="<?php echo $_assoc['picpath']; ?>" alt=""></a></i>
                    </div>
                        <div class="i_right">
                            <span class="title"><?php echo $_assoc['bookname']; ?></span>
                            <div class="all">
                            <span class="author"><?php echo $_assoc['bookauthor']; ?></span>
                            <span class="sort_f"><?php
                                  switch($_assoc['typeid'])
                                  {
                                    case 1:echo "玄幻" ;break;
                                    case 2:echo "奇幻";break;
                                    case 3:echo "武侠";break;
                                    case 4:echo "仙侠";break;
                                    case 5:echo "都市";break;
                                    case 6:echo "现实";break;
                                    case 7:echo "历史";break;
                                    case 8:echo "军事";break;
                                    case 9:echo "校园";break;
                                    case 10:echo "游戏";break;
                                    case 11:echo "言情";break;
                                    case 12:echo "灵异";break;
                                    case 13:echo "N次元";break;

                              }
                             ?>·</span>
                            <span class="sort_z"><?php echo $_assoc['lable']; ?></span>
                            <span class="atate"><?php
                                  switch($_assoc['isend'])
                                  {
                                    case 1:echo "完结" ;break;
                                    case 0:echo "连载中";break;

                              }
                             ?></span>
                            </div>
                            <p><?php echo $_assoc['descripation']; ?></p>
                            <span class="zishu_total"><?php echo $_assoc['words'].'  万字'; ?></span>
                        </div>

                </li>
                   <?php
      }
        ?>
            </ul>

        </div>

        <div class="num">
            <ul>
            <?php
                for($i=0;$i<$_pagesnum;$i++)
                {
                  echo '<li><a href="allbooks.php?page='.($i+1).'">'.($i+1).'</a></li>';
                }
                echo '<li><a href="allbooks.php?page='.($_page+1).'" >></a></li>';
            ?>


              <input type="text" name="" class="tiao" value="">
              <?php
                  echo "<script>$('.tiao').val()</script>"
              ?>
              <?php echo '<span class="go"><a href="allbooks.php?page=

                  '."<script>$('.tiao').val();</script>".'
              " title=""></a>go</span>' ?>
            </ul>
        </div>


    </div>



</div>
<?php
    require 'include/zhuce.footer.inc.php';
?>
</body>
</html>